package gov.pbc.nn.kjgl.maintenance.view;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bstek.bdf2.export.interceptor.IDataInterceptor;

import gov.pbc.nn.kjgl.maintenance.entity.SysEmergencyPlanDept;
import gov.pbc.nn.kjgl.maintenance.entity.SysEmergencyPlanHeader;
import gov.pbc.nn.kjgl.maintenance.entity.SysEmergencyRehearsalStep;
import gov.pbc.nn.uflo.entity.Opinion;
@Component("interceptorNameExcel")
public class InterceptorNameExcel implements IDataInterceptor{
	
	@Autowired
	private SysEmergencyPlanPR sysEmergencyPlanPR;
	
	@Override
	public String getDesc() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "interceptorNameExcel";
	}

	@Override
	public void interceptAutoFormData(List<Map<String, Object>> arg0) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void interceptGridData(List<Map<String, Object>> list) throws Exception {
		List<Map<String, Object>> exportList = new ArrayList<Map<String, Object>>();
		for (Map<String, Object> map : list) {
			Map<String, Object> row = new HashMap<String, Object>();
			exportList.add(row);
			String id = (String) map.get("id");
			int state=(int) map.get("state");
			String sysName = (String) map.get("sysName");
			String title=(String) map.get("title");
			Date startDate=(Date) map.get("startDate");
			String content=(String) map.get("content");
			String createUserCname=(String) map.get("createUserCname");
			row.put("sysName",sysName);
			row.put("title",title);
			row.put("state",state);
			row.put("content",content);
			row.put("startDate",startDate);	
			row.put("createUserCname",createUserCname);
			List<SysEmergencyPlanDept>  planDept =sysEmergencyPlanPR.loadSysEmergencyPlanDept(id);
			List<SysEmergencyPlanHeader>  planHeader =sysEmergencyPlanPR.loadSysEmergencyPlanHeader(id);
			if(planDept!=null){
				for (SysEmergencyPlanDept sysPlanDept : planDept) {
					Map<String, Object> row3 = new HashMap<String, Object>();
					exportList.add(row3);
					row3.put("deptName", sysPlanDept.getDeptName());
				}
			}
			if(planHeader!=null){
				for (SysEmergencyPlanHeader sysPlanHeader : planHeader) {
					Map<String, Object> row2 = new HashMap<String, Object>();
					exportList.add(row2);
					row2.put("cname", sysPlanHeader.getCname());
				}
			}
			row = new HashMap<String, Object>();
			exportList.add(row);
		}
		list.clear();
		list.addAll(exportList);
	}
}
